package com.tongji.seller.view
{
	import com.tongji.seller.events.GetStoreItemsEvent;
	import com.tongji.seller.events.GetTypesEvent;
	import com.tongji.seller.events.utilsEvent.ChangeStepEvent;
	import com.tongji.seller.model.UserModel;
	import com.tongji.seller.utils.PopUpAdmin;
	import com.tongji.seller.view.popup.SavedSceneTitleWindow;
	
	import flash.events.MouseEvent;
	
	import mx.controls.Alert;
	import mx.managers.PopUpManager;
	import mx.skins.halo.WindowBackground;
	
	import org.robotlegs.mvcs.Mediator;
	
	/**
	 *
	 * @author caddy
	 * @date 2011-11-26
	 */
	public class MainCompMediator extends Mediator
	{
		[Inject]
		public var view:MainComp;
		
		[Inject]
		public var userModel:UserModel;
		
		override public function onRegister():void
		{
			addContextListener(ChangeStepEvent.TO_FIRST_STEP, changeViewHandler, ChangeStepEvent);
			addContextListener(ChangeStepEvent.TO_SECOND_STEP, changeViewHandler, ChangeStepEvent);
			addContextListener(ChangeStepEvent.TO_THIRD_STEP, changeViewHandler, ChangeStepEvent);
		}
		
		private function mySceneHandler(event:MouseEvent):void
		{
			PopUpAdmin.popupCenterWindow(PopUpAdmin.MY_SCENE_TITLE_WIN, view.parent.parent, mediatorMap);
		}
		
		private function changeViewHandler(event:ChangeStepEvent):void
		{
			view.currentState = "normal";
			eventMap.mapListener(view.myScene, MouseEvent.CLICK, mySceneHandler, MouseEvent);
			if (userModel.currentState == 0)
			{
				view.secondStep.enabled = true;
				view.thirdStep.enabled = true;
				switch (event.type)
				{
					case ChangeStepEvent.TO_FIRST_STEP:
						view.firstStep.selected = true;
						view.viewstack.selectedIndex = 0;
						break;
					case ChangeStepEvent.TO_SECOND_STEP:
						view.secondStep.selected = true;
						view.viewstack.selectedIndex = 1;
						break;
					case ChangeStepEvent.TO_THIRD_STEP:
						view.thirdStep.selected = true;
						view.viewstack.selectedIndex = 2;
						break;
					default:break;
				}
			}
			else
			{
				switch (event.type)
				{
					case ChangeStepEvent.TO_FIRST_STEP:
						view.firstStep.selected = true;
						view.viewstack.selectedIndex = 0;
						view.secondStep.enabled = false;
						view.thirdStep.enabled = false;
						break;
					case ChangeStepEvent.TO_SECOND_STEP:
						view.secondStep.selected = true;
						view.viewstack.selectedIndex = 1;
						view.secondStep.enabled = true;
						break;
					case ChangeStepEvent.TO_THIRD_STEP:
						view.thirdStep.selected = true;
						view.viewstack.selectedIndex = 2;
						view.thirdStep.enabled = true;
						break;
					default:break;
				}
			}
					
		}
	}
}